import React from 'react';
import { Form, Row, DatePicker, Button, Select, Input, Col } from 'antd';
import moment from 'moment';
const FormItem = Form.Item;
const { RangePicker } = DatePicker;
const { Option } = Select;

const SearchForm = ({ form: { getFieldDecorator, getFieldsValue }, onSearch, onClick, advanced, searchItem, resetForm, workStatusList, addFrom }) => {
  const onHandleAdvanced = () => {
    if (onClick) {
      onClick();
    }
  };

  const formItemLayout = {
    // 抽屉里面Form。二列的布局比例
    labelCol: {
      span: 8
    },
    wrapperCol: {
      span: 16
    }
  };
  return (
    <Form className="search-form">
      <Row gutter={24}>
        <Col span={5}>
          <FormItem label="批号"{...formItemLayout}>
            {getFieldDecorator('batchNo', {
              initialValue: searchItem.batchNo || '',
              getValueFromEvent: (event) => {
                return event.target.value.replace(/\s+/g, "")
              },
            })(
              <Input placeholder='请输入批号' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="车间"{...formItemLayout}>
            {getFieldDecorator('department', {
              initialValue: searchItem.department || undefined,
              rules: [{
                required: true,
                message: '请选择车间'
              }]
            })(
              // <Input placeholder='请输入车间' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
              <Select placeholder='请选择车间' allowClear >
                {
                  addFrom.map(item => {
                    return <Option key={item.workShop}>{item.workShop}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="日期筛选"{...formItemLayout}>
            {getFieldDecorator('firstDeliveryDate', {
              initialValue: [
                moment(searchItem.startTime, 'YYYY-MM-DD'),
                moment(searchItem.endTime, 'YYYY-MM-DD')
              ] || undefined
            })(
              <RangePicker allowClear />
            )}
          </FormItem>
        </Col>
        <Col span={5}>
          <FormItem label="状态"{...formItemLayout}>
            {getFieldDecorator('isStates', {
              initialValue: searchItem.isStates || undefined
            })(
              // <Input placeholder='请输入状态' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
              <Select placeholder='请选择状态' allowClear >
                {
                  workStatusList.map(item => {
                    return <Option key={item.id}>{item.value}</Option>
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>
        <Col span={4} style={{ display: 'flex' }} className="serarch-btns">
          <FormItem>
            <Button icon="search" type="primary" onClick={() => onSearch(getFieldsValue())}>
              {'查询'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="primary" icon={advanced ? 'up' : 'down'} onClick={() => onHandleAdvanced()}>
              {'展开'}
            </Button>
          </FormItem>
          <FormItem>

            <Button type="default" icon={'redo'} onClick={() => resetForm()}>
              {'重置'}
            </Button>
          </FormItem>
        </Col>
      </Row>
      <Row gutter={24}>

        {
          advanced ?
            <Col span={5}>
              <FormItem label="机型"{...formItemLayout}>
                {getFieldDecorator('model', {
                  initialValue: searchItem.model || '',
                  getValueFromEvent: (event) => {
                    return event.target.value.replace(/\s+/g, "")
                  },
                })(
                  <Input placeholder='请输入机型' allowClear onPressEnter={() => onSearch(getFieldsValue())} />
                )}
              </FormItem>
            </Col> : ''
        }
      </Row>

    </Form>
  );
};

export default Form.create()(SearchForm);
